﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RR408Response", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR408Response))]
    public class RR408ResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRR408Response clazz;
        
        public RR408ResponseSerializer(IRR408Response clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Veakood");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Veakood))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("Veatekst");
            if (clazz.Veatekst!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Veatekst))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Veatekst");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Isikud");
            if (clazz.Isikud!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute(">>>RR408Response>Isikud>Isikud", "http://producers.rr.xtee.riik.ee/producer/rr", clazz.Isikud.Count);
                for (int x = 0; ((clazz.Isikud != null) 
                            && (x < clazz.Isikud.Count)); x = (x + 1)) {
                    if (clazz.Isikud[x]!=null) {
                        Writer.WriteStartElement("Isikud");
                        global::Xtee.Core.SerializationMetadata metaIsikud = this.GetMetaData(clazz.Isikud[x]);
                        Writer.WriteTypeAttribute(metaIsikud.TypeQualifiedName.Namespace, metaIsikud.TypeQualifiedName.Name);
                        metaIsikud.NewSerializer(clazz.Isikud[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isikud");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Veakood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR408Response>Veakood");
                }
                clazz.Veakood = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("Veakood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR408Response>Veakood", Reader.LocalName);
            }
            if (Reader.LocalName=="Veatekst") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR408Response>Veatekst");
                }
                clazz.Veatekst = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Veatekst")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR408Response>Veatekst", Reader.LocalName);
            }
            if (Reader.LocalName=="Isikud") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR408Response>Isikud");
                }
                clazz.Isikud = new System.Collections.Generic.List<RR408Response.IIsikudType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("Isikud");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "Isikud")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>RR408Response>Isikud>Isikud");
                        }
                        global::Xtee.Core.SerializationMetadata metaIsikud = this.GetMetaData<RR408Response.IIsikudType>(Reader, ">>>RR408Response>Isikud>Isikud", "http://producers.rr.xtee.riik.ee/producer/rr");
                        RR408Response.IIsikudType item = metaIsikud.NewEntity<RR408Response.IIsikudType>();
                        clazz.Isikud.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("Isikud");
                            metaIsikud.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR408Response>Isikud", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>RR408Response>Isikud>Isikud", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR408Response.IsikudType))]
        public class IsikudTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected RR408Response.IIsikudType clazz;
            
            public IsikudTypeSerializer(RR408Response.IIsikudType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("Isikud.Isikukood");
                if (clazz.IsikudIsikukood!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudIsikukood))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudIsikukood");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.Eesnimi");
                if (clazz.IsikudEesnimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudEesnimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudEesnimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.Perenimi");
                if (clazz.IsikudPerenimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudPerenimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudPerenimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.IsikuOlek");
                if (clazz.IsikudIsikuOlek!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudIsikuOlek))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudIsikuOlek");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.Surmakuupaev");
                if (clazz.IsikudSurmakuupaev!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudSurmakuupaev))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudSurmakuupaev");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.Koda");
                if (clazz.IsikudKoda!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudKoda))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudKoda");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.Kodakondsus");
                if (clazz.IsikudKodakondsus!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudKodakondsus))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudKodakondsus");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.EelKoda");
                if (clazz.IsikudEelKoda!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudEelKoda))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudEelKoda");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.EelKodakondsus");
                if (clazz.IsikudEelKodakondsus!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudEelKodakondsus))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudEelKodakondsus");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.Elukohatyyp");
                if (clazz.IsikudElukohatyyp!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudElukohatyyp))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudElukohatyyp");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.ElukohaAadress");
                if (clazz.IsikudElukohaAadress!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudElukohaAadress))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudElukohaAadress");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.Postiindeks");
                if (clazz.IsikudPostiindeks!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudPostiindeks))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudPostiindeks");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Isikud.Sideandmed");
                if (clazz.IsikudSideandmed!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikudSideandmed))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikudSideandmed");
                }
                Writer.WriteEndElement();
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="Isikud.Isikukood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR408Response>Isikud>Isikud>Isikud.Isikukood");
                    }
                    clazz.IsikudIsikukood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.Isikukood")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR408Response>Isikud>Isikud>Isikud.Isikukood", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.Eesnimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR408Response>Isikud>Isikud>Isikud.Eesnimi");
                    }
                    clazz.IsikudEesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.Eesnimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR408Response>Isikud>Isikud>Isikud.Eesnimi", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.Perenimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR408Response>Isikud>Isikud>Isikud.Perenimi");
                    }
                    clazz.IsikudPerenimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.Perenimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR408Response>Isikud>Isikud>Isikud.Perenimi", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.IsikuOlek") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR408Response>Isikud>Isikud>Isikud.IsikuOlek");
                    }
                    clazz.IsikudIsikuOlek = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.IsikuOlek")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR408Response>Isikud>Isikud>Isikud.IsikuOlek", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.Surmakuupaev") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR408Response>Isikud>Isikud>Isikud.Surmakuupaev");
                    }
                    clazz.IsikudSurmakuupaev = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.Surmakuupaev")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR408Response>Isikud>Isikud>Isikud.Surmakuupaev", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.Koda") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR408Response>Isikud>Isikud>Isikud.Koda");
                    }
                    clazz.IsikudKoda = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.Koda")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR408Response>Isikud>Isikud>Isikud.Koda", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.Kodakondsus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR408Response>Isikud>Isikud>Isikud.Kodakondsus");
                    }
                    clazz.IsikudKodakondsus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.Kodakondsus")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR408Response>Isikud>Isikud>Isikud.Kodakondsus", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.EelKoda") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR408Response>Isikud>Isikud>Isikud.EelKoda");
                    }
                    clazz.IsikudEelKoda = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.EelKoda")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR408Response>Isikud>Isikud>Isikud.EelKoda", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.EelKodakondsus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR408Response>Isikud>Isikud>Isikud.EelKodakondsus");
                    }
                    clazz.IsikudEelKodakondsus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.EelKodakondsus")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR408Response>Isikud>Isikud>Isikud.EelKodakondsus", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.Elukohatyyp") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR408Response>Isikud>Isikud>Isikud.Elukohatyyp");
                    }
                    clazz.IsikudElukohatyyp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.Elukohatyyp")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR408Response>Isikud>Isikud>Isikud.Elukohatyyp", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.ElukohaAadress") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR408Response>Isikud>Isikud>Isikud.ElukohaAadress");
                    }
                    clazz.IsikudElukohaAadress = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.ElukohaAadress")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR408Response>Isikud>Isikud>Isikud.ElukohaAadress", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.Postiindeks") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR408Response>Isikud>Isikud>Isikud.Postiindeks");
                    }
                    clazz.IsikudPostiindeks = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.Postiindeks")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR408Response>Isikud>Isikud>Isikud.Postiindeks", Reader.LocalName);
                }
                if (Reader.LocalName=="Isikud.Sideandmed") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR408Response>Isikud>Isikud>Isikud.Sideandmed");
                    }
                    clazz.IsikudSideandmed = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikud.Sideandmed")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR408Response>Isikud>Isikud>Isikud.Sideandmed", Reader.LocalName);
                }
            }
        }
    }
}
